package com.safetys.co.idaas;

import com.assembly.co.safetys.SpringContextUtil;
import com.safetys.co.idaas.entity.Settings;
import com.safetys.co.idaas.service.IdaasService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
@ConditionalOnClass({IdaasService.class})
@EnableConfigurationProperties(IdaasProperties.class)
public class IdaasAutoConfiguration {

	@Autowired
	private IdaasProperties idaasProperties;
	
	@Autowired
	private SpringContextUtil springContextUtil;
	
	@Bean
	public IdaasService idaasService () {
		
		log.info("IdaasService Profile is {}", springContextUtil.getActiveProfile());
		
		Settings settings = new Settings();
		BeanUtils.copyProperties(idaasProperties, settings);
		IdaasService idaasService = IdaasService.getInstance(settings);
		return idaasService;
	}
}
